/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller.user;

import java.util.List;
import queenb.net.entitybean.S200;
import queenb.web.controller.QueenbController;
import queenb.web.store.S200Store;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class S200Controller extends QueenbController {

    private int PS200;
    private String SV201;
    private String SV202;
    private String SV203;
    private String SV204;
    private int SV216;//phân biệt mã tour và chuyện mục công việc
    private S200Store s200Store;
    private boolean flag;
    private String pageLoad;

    public S200Controller() {
        s200Store = new S200Store();
        Object sv216Object = getRequest().getParameter("SV216");
        Object pv200Object = getRequest().getParameter("ps200");
        Object objPageLoad = getRequest().getParameter("page");
        if (objPageLoad != null) {
            this.pageLoad = objPageLoad.toString();
            System.out.println("page load --------------" + objPageLoad);
        }
        if (getRequest().getParameter("action") != null) {
            String action = getRequest().getParameter("action");
            if (action.equals("add")) {
                flag = true;
                try {
                     this.SV216 = Util.parseInt(sv216Object);
                } catch (Exception e) {
                }
            }
            if (action.equals("edit")) {
                flag = false;
                this.PS200 = Util.parseInt(pv200Object);
                 System.out.println("l----------" + PS200);
                try {
                     this.SV216 = Util.parseInt(sv216Object);
                } catch (Exception e) {
                }
               
                getListS200DetailEdit(PS200);
            }
        }
    }

    public void getListS200DetailEdit(int pv200i) {
        try {
                List<S200> listV200ByID = getListS200All();
                if (listV200ByID.size() > 0) {
                    for (int i = 0; i < listV200ByID.size(); i++) {
                        if (listV200ByID.get(i).getPS200() == PS200) {
                            this.SV201 = listV200ByID.get(i).getSV201();
                            this.SV202 = listV200ByID.get(i).getSV202();
                            this.SV203 = listV200ByID.get(i).getSV203();
                            this.SV204 = listV200ByID.get(i).getSV204();
                            this.SV216 = listV200ByID.get(i).getSV216();
                            break;
                        }
                    }
                }
            } catch (Exception ex) {
                System.out.println("ERROR : " + ex.getMessage());
            }
        
//        
//        this.PS200 = pv200i;
//        if (SV216 == 0) {
//            try {
//                List<S200> listV200ByID = getListS200All();
//                if (listV200ByID.size() > 0) {
//                    for (int i = 0; i < listV200ByID.size(); i++) {
//                        if (listV200ByID.get(i).getPS200() == PS200) {
//                            this.SV201 = listV200ByID.get(i).getSV201();
//                            this.SV202 = listV200ByID.get(i).getSV202();
//                            this.SV203 = listV200ByID.get(i).getSV203();
//                            this.SV204 = listV200ByID.get(i).getSV204();
//                            this.SV216 = listV200ByID.get(i).getSV216();
//                            break;
//                        }
//                    }
//                }
//            } catch (Exception ex) {
//                System.out.println("ERROR : " + ex.getMessage());
//            }
//        } else {
//            try {
//                List<S200> listV200ByID = getListS200codeWork();
//                if (listV200ByID.size() > 0) {
//                    for (int i = 0; i < listV200ByID.size(); i++) {
//                        if (listV200ByID.get(i).getPS200() == PS200) {
//                            this.SV201 = listV200ByID.get(i).getSV201();
//                            this.SV202 = listV200ByID.get(i).getSV202();
//                            this.SV203 = listV200ByID.get(i).getSV203();
//                            this.SV204 = listV200ByID.get(i).getSV204();
//                            this.SV216 = listV200ByID.get(i).getSV216();
//                            break;
//                        }
//                    }
//                }
//            } catch (Exception ex) {
//                System.out.println("ERROR : " + ex.getMessage());
//            }
//        }
    }

    public List<S200> getListS200All() {
        try {
            List<S200> listS200 = s200Store.getListS200All(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            System.out.println("líttttttttttttttttttttttttt" + listS200.size());
            return listS200;
        } catch (Exception e) {
            return null;
        }
    }

    public List<S200> getListS200codeWork() {
        try {
            List<S200> listS200 = s200Store.getListS200All(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            return listS200;
        } catch (Exception e) {
            return null;
        }
    }

    public void updateS200() {
        System.out.println("sv203 --------------" + SV201);
        System.out.println("sv204 --------------" + SV204);
        if (flag == true) {
            int count = s200Store.updateS200( getLogin().getModule(), getLogin().getCompanyNo(),PS200,SV201, SV202, SV203, SV204,getLogin().getUserName());
            if (count >= 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        } else {
            int count = s200Store.updateS200( getLogin().getModule(), getLogin().getCompanyNo(),PS200,SV201, SV202, SV203, SV204,getLogin().getUserName());
            if (count >= 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
               
            } else {
                 showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        }
        
        sendRedirectUrlTab("setting.jsp?tab=header7&"+Util.convertMD5(getRequest().getRequestURI()));
//        System.out.println("page load -------------"+pageLoad);
//        if (pageLoad.equals("managerTour.jsp")) {
//            sendRedirect(pageLoad);
//        } else {
//            if (SV216 == 0) {
//                sendRedirect("setting.jsp?tab=header6");
//            } else if (SV216 == 1) {
//                sendRedirect("setting.jsp?tab=header7");
//            }
//        }
    }

    /**
     * @return the PS200
     */
    public int getPS200() {
        return PS200;
    }

    /**
     * @param PS200 the PS200 to set
     */
    public void setPS200(int PS200) {
        this.PS200 = PS200;
    }

    /**
     * @return the SV201
     */
    public String getSV201() {
        return SV201;
    }

    /**
     * @param SV201 the SV201 to set
     */
    public void setSV201(String SV201) {
        this.SV201 = SV201;
    }

    /**
     * @return the SV202
     */
    public String getSV202() {
        return SV202;
    }

    /**
     * @param SV202 the SV202 to set
     */
    public void setSV202(String SV202) {
        this.SV202 = SV202;
    }

    /**
     * @return the SV216
     */
    public int getSV216() {
        return SV216;
    }

    /**
     * @param SV216 the SV216 to set
     */
    public void setSV216(int SV216) {
        this.SV216 = SV216;
    }

    /**
     * @return the pageLoad
     */
    public String getPageLoad() {
        return pageLoad;
    }

    /**
     * @param pageLoad the pageLoad to set
     */
    public void setPageLoad(String pageLoad) {
        this.pageLoad = pageLoad;
    }

    /**
     * @return the SV203
     */
    public String getSV203() {
        return SV203;
    }

    /**
     * @param SV203 the SV203 to set
     */
    public void setSV203(String SV203) {
        this.SV203 = SV203;
    }

    /**
     * @return the SV204
     */
    public String getSV204() {
        return SV204;
    }

    /**
     * @param SV204 the SV204 to set
     */
    public void setSV204(String SV204) {
        this.SV204 = SV204;
    }
    
}
